<template>
  <div>
    <span>&nbsp;</span>
    <el-form
      :inline="true"
      :model="detailedQuery"
      class="demo-form-inline"
      style="border-radius: 4px"
    >
      <span>&nbsp;</span>
      <span>&nbsp;</span>
      <el-form-item label="名称">
        <el-input v-model="detailedQuery.title" placeholder="名称"></el-input>
      </el-form-item>
      <el-form-item label="金额">
        <el-input v-model="detailedQuery.num" placeholder="金额"></el-input>
      </el-form-item>
      <el-form-item label="类型">
        <el-select v-model="detailedQuery.type" placeholder="类型">
          <el-option label="收入" value="1"></el-option>
          <el-option label="支出" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="时间">
        <el-col :span="18">
          <el-date-picker
            v-model="detailedQuery.time"
            type="daterange"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            range-separator=" | "
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getpageList()">查询</el-button>
        <el-button type="success" @click="empty">清空</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="detailedlist" border style="width: 100%" :row-class-name="tableRowClassName">
      <el-table-column label="序号" width="100" align="center">
        <template slot-scope="scope">{{ (page - 1) * limit + scope.$index + 1 }}</template>
      </el-table-column>
      <el-table-column prop="gmtCreate" label="日期" align="center" width="220"></el-table-column>
      <el-table-column prop="title" label="明细" align="center" width="220"></el-table-column>
      <el-table-column prop="num" label="金额" align="center"></el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-popover
            placement="bottom"
            width="200"
            trigger="click"
          >
          {{description}}
            <el-button type="success" size="mini" round="" slot="reference" @click="getdescription(scope.row.id)">查看备注</el-button>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <router-link :to="'/zw/edit/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit" round>修改</el-button>
          </router-link>
          <el-button
            type="danger"
            size="mini"
            icon="el-icon-delete"
            @click="removedetailed(scope.row.id)"
            round
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      :current-page="page"
      :page-size="limit"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getpageList"
    />
  </div>
</template>

<style>
.el-table .pay {
  background: #f5f5f500;
}

.el-table .income {
  background: #fbfcfb00;
}
</style>

<script>
import detailed from "@/api/zw/zwlb";

export default {
  data() {
    return {
      zwlist: [],
      detailedlist: [],
      page: 1, //当前页数
      total: 0, //总记录数
      limit: 10, //每页记录数
      detailedQuery: {}, //条件封装对象,
      description: ""

    };
  },
  created() {
    this.getpageList();
  },
  methods: {
    getdescription(id){
      detailed.getDescription(id).then(response=>{
        this.description=response.data.description
      })
    },
    empty() {
      this.detailedQuery = {};
      this.getpageList()
    },
    tableRowClassName({ row, rowIndex }) {
      if (row.type === "2") {
        return "pay";
      } else {
        return "income";
      }
    },
    getpageList(page = 1) {
      this.page = page;
      detailed
        .pageList(this.page,this.limit,this.detailedQuery)
        .then(response => {
          this.total = response.data.total;
          this.detailedlist = response.data.records;
        });
    },
    removedetailed(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        //点击确定，执行删除方法
        //执行删除方法
        detailed.removedetailed(id).then(response => {
          this.$message({
            type: "success",
            message: "删除成功!"
          }),
            //回到列表页面，刷新
            this.getpageList();
        });
      });
    }
  }
};
</script>